<style>
    input.form-control{width:220px;border:1px solid rgb(204, 204, 204);padding:0 10px;height:30px;}
</style>
<h4>添加流程</h4>
<form id="AddProcess" class="form-horizontal" method="post" action="{:U('Admin/BusinessProcess/add')}">
    <input type="hidden" name="BussID" value="{$businessId}"/>
    <input type="hidden" name="top" value="{$top}"/>
    <input type="hidden" name="left" value="{$left}" />
    <div class="control-group">
        <label for="Name" class="control-label">流程名称*</label>
        <div class="controls">
            <input type="text" class="form-control" name="Name" id="Name" placeholder="流程名称">
        </div>
    </div>
    <div class="control-group">
        <label for="BPType" class="control-label">流程类型*</label>
        <div class="controls">
            <select id="BPType" name="BPType" class="form-control">
                <foreach name='BPType' item='vo'>
                    <option {$selected} value="{$key}">{$vo}</option>
                </foreach>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label for="HandleDpt" class="control-label">主办部门</label>
        <div class="controls">
            <input type="hidden" class="form-control" name="HandleDptID" id="HandleDptID" placeholder="主办部门">
            <input style="cursor:pointer;background:url('./Public/Admin/img/Arrow-Icon.png') right center no-repeat" type="text" class="form-control" name="HandleDpt" id="HandleDpt" placeholder="主办部门">
        </div>
    </div>
    <div class="control-group">
        <label for="HandleUser" class="control-label">主办人</label>
        <div class="controls">
            <input type="hidden" class="form-control" name="HandleUserID" id="HandleUserID" placeholder="主办人">
            <input style="cursor:pointer;background:url('./Public/Admin/img/Arrow-Icon.png') right center no-repeat" type="text" class="form-control" name="HandleUser" id="HandleUser" placeholder="主办人">
        </div>
    </div>
    <div class="control-group">
        <label for="LimitTime" class="control-label">办理时限</label>
        <div class="controls">
            <input id="LimitTime" name="LimitTime" type="text" class="form-control"/> ( / 天)
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <button id="addBtn" type="button" class="btn btn-success">保存</button>
            <button style="margin-left:15px;" type="button" class="btn btn-default" data-dismiss="modal">返回</button>
        </div>
    </div>
</form>
<script>
    var memberSelector = new MemberSelector('#HandleDpt',{
        title : '选择部门',
        type : 2
    },function(itemList){
        var ids = '';
        var titles = '';
        for(var i = 0; i < itemList.length; i++){
            var id = itemList[i].id;
            var title = itemList[i].title;
            ids += id;
            ids += (i+1 == itemList.length)?'':',';
            titles += title;
            titles += (i+1 == itemList.length)?'':',';
        }
        $('input[name=HandleDptID]').val(ids);
        $('input[name=HandleDpt]').val(titles);

        console.log(itemList);
    });
    var memberSelector2 = new MemberSelector('#HandleUser',{
        title : '选择人员',
        type : 1
    },function(itemList){
        var ids = '';
        var titles = '';
        for(var i = 0; i < itemList.length; i++){
            var id = itemList[i].id;
            var title = itemList[i].title;
            ids += id;
            ids += (i+1 == itemList.length)?'':',';
            titles += title;
            titles += (i+1 == itemList.length)?'':',';
        }
        $('input[name=HandleUserID]').val(ids);
        $('input[name=HandleUser]').val(titles);

        console.log(itemList);
    });


    $('button#addBtn').click(function(){

        var data = {};
        data['BusiID'] = $('input[name=BussID]').val();
        data['Name'] = $.trim($('input[name=Name]').val());
        data['BPType'] = $('select[name=BPType]').val();
        data['HandleDptID'] = $('input[name=HandleDptID]').val();
        data['HandleUserID'] = $('input[name=HandleUserID]').val();
        data['LimitTime'] = $.trim($('input[name=LimitTime]').val());
        data['top'] = $('input[name=top]').val();
        data['left'] = $('input[name=left]').val();
        if(!data['Name']){
            alert('请填写流程名称');return;
        }
        console.log(data);
        var url = $('form#AddProcess').attr('action');
        $.ajax({
            url : url,
            type : 'post',
            dataType : 'json',
            data : {
                data : data
            },
            success : function(data){
                console.log(data);
                if(data.status===1){
                    location.reload();
                }
            },
            error : function(data){
                console.log(data);
            }
        });
    });

</script>